package com.api.projectY.controller;

import com.api.common.core.controller.BaseController;
import com.api.common.core.domain.AjaxResult;
import com.api.common.core.page.TableDataInfo;
import com.api.core.domain.vo.MonitoredGroupVo;
import com.api.core.service.IMonitoredGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/monitoredGroup")
public class MonitoredGroupController extends BaseController {
    @Autowired
    IMonitoredGroupService monitoredGroupService;
    @PostMapping("list")
    public TableDataInfo list(@RequestHeader("App-Language") String appLang,
                              @RequestBody MonitoredGroupVo vo){
        vo.setAppLang(appLang);
        if(vo.getPageNum()>0) {
            startPageByPost(vo.getPageNum(), vo.getPageSize());
        }
        return getDataTable(monitoredGroupService.list(vo));
    }

    @PostMapping("info")
    public AjaxResult info(@RequestHeader("App-Language") String appLang,
                           @RequestBody MonitoredGroupVo vo){
        try {
            return AjaxResult.success(monitoredGroupService.item(vo));
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
    @PostMapping("create")
    public AjaxResult add(@RequestHeader("App-Language") String appLang,
                           @RequestBody MonitoredGroupVo vo){
        try {
            return AjaxResult.success(monitoredGroupService.create(vo));
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
    }
    @PostMapping("modify")
    public AjaxResult modify(@RequestHeader("App-Language") String appLang,
                          @RequestBody MonitoredGroupVo vo){
        try {
            return AjaxResult.success(monitoredGroupService.modify(vo));
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
    @PostMapping("remove")
    public AjaxResult remove(@RequestHeader("App-Language") String appLang,
                          @RequestBody MonitoredGroupVo vo){
        try {
            monitoredGroupService.delete(vo);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
